package com.new2i.action;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.new2i.aop.LoginInterceptor;
import com.new2i.model.DoctorEntity;
import com.new2i.model.EmrNeonatusEntity;
import com.new2i.service.able.EmrService;

/**
 * 病例管理视图视图控制器－视图
 * 
 * @since 2015/09/02
 * @author 2i
 *
 */
@Controller
@RequestMapping("page/emr")
public class EmrPageController {

	@Autowired
	private EmrService mEmrService;

	/**
	 * 病历列表界面
	 * 
	 * @since 2015/09/02
	 * @author 2i
	 * @param request
	 * @param response
	 * @param code
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView emrListPage(HttpServletRequest request, HttpServletResponse response, String code) {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("/views/emr_list.jsp");
		return mav;
	}

	/**
	 * 病例详情
	 * 
	 * @since 2015/09/06
	 * @author 2i
	 * @param request
	 * @param response
	 * @param code
	 * @return
	 */
	@LoginInterceptor
	@RequestMapping(value = "/{emr_neonatus_id}", method = RequestMethod.GET)
	public ModelAndView emrInfoPage(@PathVariable int emr_neonatus_id, HttpServletRequest request,
			HttpServletResponse response, DoctorEntity dcotor) {
		ModelAndView mav = new ModelAndView();
		EmrNeonatusEntity emr = new EmrNeonatusEntity();
		emr.setEmr_neonatus_id(emr_neonatus_id);
		emr.setDoctor_id(dcotor.getDoctor_id());
		HashMap<String, Object> emrInfo = mEmrService.getEmrInfoById(emr);
		mav.setViewName("/views/user_emr_info.jsp");
		mav.addObject("user_emr_info", emrInfo);
		return mav;
	}

	/**
	 * 病例修改页面
	 * 
	 * @since 2015/09/06
	 * @author 2i
	 * @param request
	 * @param response
	 * @param code
	 * @return
	 */
	@LoginInterceptor
	@RequestMapping("/info/update")
	public ModelAndView emrInfoPage(HttpServletRequest request, HttpServletResponse response, DoctorEntity dcotor,
			EmrNeonatusEntity emr) {
		ModelAndView mav = new ModelAndView();
		emr.setDoctor_id(dcotor.getDoctor_id());
		HashMap<String, Object> emrInfo = mEmrService.getEmrInfoById(emr);
		mav.setViewName("/views/edit_user_emr_info.jsp");
		mav.addObject("edit_user_emr_info", emrInfo);
		return mav;
	}
}
